@extends('backstage.layout.master')
@section('title', '添加产品模板')
@section('style')
    <!-- page specific plugin styles -->
    <link rel="stylesheet" href="backstage/assets/css/jquery-ui-1.10.3.custom.min.css"/>
    <link rel="stylesheet" href="backstage/assets/css/chosen.css"/>
    <link rel="stylesheet" href="backstage/assets/css/colorpicker.css"/>
    <!-- fonts -->
    <style>
        .ace-file-input input[type=file] {
            position: static;
        }

        .ace-nav {
            height: 10px;
        }
        .ui-datepicker {
            width: 18em;
        }
        .ui-datepicker{
            width: 15em;
            padding-left: 1em;
        }
        .navbar {
            margin-bottom: 3px;
        }
    </style>
@stop
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>
        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a target="_blank" href="backstage/home" target="_blank">主页</a>
            </li>
            <li class="active">
                <a target="_blank" href="/backstage/product-temp/product-temp-list">产品模板</a>
            </li>
            <li>
                添加产品模板
            </li>
        </ul><!-- .breadcrumb -->
    </div>
    <div class="page-content">
        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="page-header">
                    <h1>
                        产品模板
                        <small>
                            <i class="icon-double-angle-right"></i>
                            添加产品模板
                        </small>
                    </h1>
                </div>
                <div class="row">
                    <div class="col-sm-12">
                        <h3 class="header smaller lighter red">产品模板说明：</h3>
                        <div class="well">
                            <h4 class="green smaller lighter">添加模板注意点：</h4>
                            1、填写默认单价各个颜色的单价相同，具体可在列表中修改</br>
                            2、填写默认库存各个颜色下各个尺码下库存相同，具体可在列表中修改</br>
                        </div>
                    </div>
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <div class="alert alert-info">
                            <i class="icon-hand-right"></i>
                            <!-- 信息-->
                        </div>
                        <div class="tabbable">
                            <ul class="nav nav-tabs padding-18 tab-size-bigger" id="myTab">
                                <li class="active">
                                    <a data-toggle="tab" href="#faq-tab-1">
                                        <i class="blue icon-edit bigger-120"></i>
                                        模板主要信息
                                    </a>
                                </li>

                                <li>
                                    <a data-toggle="tab" href="#faq-tab-2">
                                        <i class="green icon-edit bigger-120"></i>
                                        模板参数
                                    </a>
                                </li>
                            </ul>
                            <form id="form" class="form-horizontal">
                                <div class="tab-content no-border padding-24">
                                    <div id="faq-tab-1" class="tab-pane fade in active">
                                        <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                                            <tr>
                                                <td>
                                                    产品模板名称:
                                                </td>
                                                <td>
                                                    <input type="text"  name="name" style="width:190px;"  class="col-xs-10 col-sm-5"/>
                                                    <input type="hidden" name="_token" value="{{csrf_token()}}">
                                                </td>
                                            </tr>
                                            <tr class="">
                                                <td>产品品牌：</td>
                                                <td>
                                                    <input type="text"  id="brand_name" style="width:190px;"  readonly class="col-xs-10 col-sm-5"/>
                                                    <input type="hidden"  id="brand_id" name="brand_id"/>
                                                    <input  type="text" placeholder="搜索关键字"   id="brand_keyword">
                                                    <input  type="button" value="搜索" class="button" id="brand_search">
                                                    <select id="brand_search_res"  onchange="resultChange(this.options,this.options.selectedIndex)"></select>
                                                    <input type="button" value="+" class="button" onclick="addBrand()" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    邮费:
                                                </td>
                                                <td>
                                                    <input type="number" step=0.01 min=0 name="postage" value=0 tyle="width:50px;"  class="col-sm-3"/>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    默认单价:
                                                </td>
                                                <td>
                                                    <input type="number" step=0.01 min=0 name="default_price" value=0 tyle="width:50px;"  class="col-sm-3"/>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    默认库存:
                                                </td>
                                                <td>
                                                    <input type="number" step=1 min=0 name="default_stock" value=999 tyle="width:50px;"  class="col-sm-3"/>
                                                </td>
                                            </tr>
                                            <tr class="">
                                                <td>适用人群类别：</td>
                                                <td>
                                                    <input  type="text" placeholder="搜索关键字"  id="temp_crowd_keyword">
                                                    <input  type="button" value="搜索" class="button" id="crowd_search">
                                                    <select id="crowd_search_res"  onchange="resultChange(this.options,this.options.selectedIndex)"></select>
                                                    <input type="button" value="+" class="button" onclick="addProdTempCrowd()" />
                                                    <br/>
                                                    <div id="selected-crowd-div">
                                                    </div>
                                                </td>
                                            <tr class="">
                                                <td>颜色：</td>
                                                <td>
                                                    <input  type="text" placeholder="搜索关键字"  id="temp_colour_keyword">
                                                    <input  type="button" value="搜索" class="button" id="colour_search">
                                                    <select id="colour_search_res"  onchange="resultChange(this.options,this.options.selectedIndex)"></select>
                                                    <input type="button" value="+" class="button" onclick="addProdTempColour()" />
                                                    <br/>
                                                    <div id="selected-colour-div">
                                                    </div>
                                                </td>
                                            </tr>
                                            </tr>
                                        </table>
                                    </div>

                                    <div id="faq-tab-2" class="tab-pane fade">
                                        <table id="sample-table-2" class="table table-striped table-bordered table-hover">
                                            <tr class="">
                                                <td>产品模板类型：</td>
                                                <td>
                                                    <select id="temp_category_list" name="category_id" class="col-sm-2" onchange="resultChange(this.options,this.options.selectedIndex)">
                                                        <option value=0>请选择....</option>
                                                        @foreach($categorys as $category)
                                                        <option value={{isset($category->category_id)?$category->category_id:''}}>{{isset($category->name)?$category->name:''}}</option>
                                                        @endforeach
                                                    </select>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>尺码选择：</td>
                                                <td>
                                                    <select id="has_size" name="has_size" class="col-sm-2">
                                                        <option value=0>无尺码</option>
                                                        <option selected value=1>有尺码</option>
                                                    </select>
                                                </td>
                                            </tr>
                                            <tr id="size_list_tr" class="has_size">
                                                <td>尺码：</td>
                                                <td>
                                                    <select id="size_list"  onchange="resultChange(this.options,this.options.selectedIndex)"></select>
                                                    <input type="button" value="+" class="button" onclick="addProdTempSize()" />
                                                    <br/>
                                                    <div id="selected-size-div">
                                                    </div>
                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                </div>
                                <div class="clearfix form-actions">
                                    <div class="col-md-offset-5 col-md-9">
                                        <button class="btn btn-info btn-save" type="button">
                                            <i class="icon-ok bigger-110"></i>
                                            保存
                                        </button>
                                        &nbsp; &nbsp; &nbsp;
                                        <button class="btn" type="reset" id="reset_id">
                                            <i class="icon-undo bigger-110"></i>
                                            重置
                                        </button>
                                    </div>
                                </div>
                            </form>
                            <!-- PAGE CONTENT ENDS -->
                        </div><!-- /.col -->
                    </div><!-- /.row -->
                </div><!-- /.page-content -->
                @stop
@section('script')
<script src="/backstage/js/prodTemp/prodTemp.js"></script>
<script type="text/javascript">
   _token = '{{csrf_token()}}';
   $(function(){
       $('#temp_category_list').change(function() {
           var temp_category_id=$(this).val();
           if(temp_category_id==0){
               return false;
           }
           $("#size_list").html('');
           $('.attribute_tr').remove();
           $.ajax({
               type: "POST",
               url: "/backstage/product-temp/get-temp-attr-list",
               data: {'temp_category_id':temp_category_id},
               success: function (msg) {
                   if(msg.state==1){
                       var sizesHtml='';
                       var data=msg.data;
                       var sizes=data.sizes;
                       var attributes=data.attributes;
                       var attributesHtml='';
                       for(var i=0;i<sizes.length;i++) {
                           sizesHtml+='<option value='+ sizes[i] +'>'+ sizes[i] +'</option><br />';
                       }
                       $("#size_list").html(sizesHtml);
                       for(var j=0;j<attributes.length;j++) {
                           var selectHtml='';
                           var attribute=attributes[j];
                           var attr_values=attribute.attr_values;
                           attributesHtml+='<tr class="attribute_tr">';
                           attributesHtml+='<td>'+attribute.attr_name+'</td>';
                           attributesHtml+='<td>';
                           attributesHtml+='<select name="attributes[]"id="'+attribute.attr_id+'">';
                           selectHtml+='<option  value=0>不选</option><br />';
                           for(var k=0;k<attr_values.length;k++) {
                               selectHtml+='<option  value="attr_'+ attribute.attr_id+'_'+ attribute.attr_name+'_'+attr_values[k] +'">'+ attr_values[k] +'</option><br />';
                           }
                           attributesHtml+= selectHtml;
                           attributesHtml+= '</select>';
                           attributesHtml+='</td>';
                           attributesHtml+='</tr>';
                       }
                       $('#size_list_tr').after(attributesHtml);
                   }
               }, error: function () {
                   swal({title: "系统繁忙！", text: "",type: "error", timer:1000 })
               }
           });
       });
       $('#has_size').change(function() {
           var has_size=$(this).val();
           has_size=parseInt(has_size);
           if(has_size==1){
               $('.has_size').show();
           }else if(has_size==0){
               $('.has_size').hide();
           }

       });
       var save_state=1;
       $('.btn-save').click(function() {
           if(save_state==0){
               return false;
           }
           save_state==0;
           $.ajax({
               type: "POST",
               cache: true,
               url: "/backstage/product-temp/add-product-temp",
               data:$('#form').serialize(),
               success: function (msg) {
                   if(msg.state==1){
                       swal({title: "保存成功！", text: "",type: "success", timer:1000 });
                       window.location.href='/backstage/product-temp/product-temp-list';
                   }else {
                       swal({title: msg.message, text: "",type: "error", timer:1000 });
                   }
               }, error: function () {
                   swal({title: "系统繁忙！", text: "",type: "error", timer:1000 });
               }
           });
           save_state==1;
       });
   });


</script>
@stop